<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>On the Equilibrium of Planes : Flight Simulator</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <!-- <script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAABjx0oPYUSjJcMtziFJBh3BRSawe0pkAO1-1CJ_546RgjHJXXrBT5mlE2-1rbPERKa7Stscmn9QqDkA"></script> -->
  <script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAn0uHJur3cZsrvfg3Bw0YrBRYaS_WoDuBxRNdAhr21Fawr7jlsRTkPQ3YqFtGQT4IrjRBXPewqpuIYA"></script>
  <script type="text/javascript" src="sim_obf.js"></script>
  <script type="text/javascript">
  //<![CDATA[
google.load("earth", "1", {'other_params': 'sensor=false' });
google.load('maps', '2.x', {'other_params': 'sensor=false' });

var ge = null;
var geocoder;
var plane;

function el(e) { return document.getElementById(e); }

function Sample(description, url) {
  this.description = description;
  this.url = url;
  return this;
}

var samples = [];

function init() {
  geocoder = new GClientGeocoder();
  init3D();
}

function initCallback(object) {
  ge = object;
  ge.getWindow().setVisibility(true);
  ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true);
  ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);
  plane = new Plane('http://localhost:8088/hawk.kmz');
  //plane = new Plane('http://netsoc.com:8088/hawk.kmz');
}

function teleportTo(lat, lon, heading) {
	plane.teleportTo(lat, lon, heading) 
	el('latlon').value = lat +","+lon
}

function teleport() {
	var latlon = el('latlon').value
	var vals = latlon.split(",")
	var lat = parseFloat(vals[0])
	var lon = parseFloat(vals[1])
	if (isNaN(lat) || isNaN(lon)) {
		alert("Sorry, latitude and longitude must be Numbers. Latitude should be in the range -90 to 90, longitude in the range -180, to 180.")
	} else {
		if (lat < -90 || lat > 90 || lon < -180 || lon > 180)
			alert("Sorry, latitude should be in the range -90 to 90, longitude in the range -180, to 180.")
		else
			plane.teleportTo(lat,lon,0) 
	}
}

function failureCallback(err) {
    // Whoops!
}

function init3D() {
  google.earth.createInstance("map3d", initCallback, failureCallback);
}

  //]]>
  </script>
</head>
<body onload='init();' onunload="GUnload()" onkeydown="return keyDown(event);" onkeyup="return keyUp(event);">
  <div style="width: 500px; margin:0 auto;">
     <font style='font-size:0.9em;color:#0f0f0f;'>Flight Number: <b id='flightNumber'>??</b>
  </div>
  <div id='map3d_container' style="width: 500px; height: 380px; margin:0 auto;">
    <div id='map3d' style='height: 100%;'></div>
  </div>
  <div style="width: 500px; margin:0 auto;">
     <br/><b>Left:</b> Bank left <i>(rate of turn is higher at higher speeds)</i>
     <b>Right:</b> Bank right
     <br/><b>Up:</b> Accelerate <i>(releasing slowly reduces speed)</i>
     <b>Down:</b> Hit the brakes!
     </br>
	 If you get lost, return to <button onclick='javascript:teleportTo(53.4359166, -6.261181, 2.74233105);void(0);'>Dublin</button>
	 or try one of these fine international airports:</br>
	<HR WIDTH="100%"/>
	 <button onclick='javascript:teleportTo(51.464756,-0.4818963,1.55);void(0);'>Heathrow</button>
	 <button onclick='javascript:teleportTo(49.020591,2.512779,1.5);void(0);'>Charles de Gaulle</button>
	 <button onclick='javascript:teleportTo(42.889785,-85.519273,3.0);void(0);'>Gerald R. Ford</button>
	 <button onclick='javascript:teleportTo(-33.93028,151.171875,2.95);void(0);'>Sydney</button>
	 <button onclick='javascript:teleportTo(41.782353,12.24025,-0.31);void(0);'>Leonardo da Vinci</button>
	 <button onclick='javascript:teleportTo(37.514507,-122.252509,2.4);void(0);'>San Carlos</button>
	 <button onclick='javascript:teleportTo(48.651752,-123.439078,1.86);void(0);'>Victoria</button>
	 <button onclick='javascript:teleportTo(38.842248,-77.036819,-0.08);void(0);'>Ronald Reagan</button>
	 <button onclick='javascript:teleportTo(42.350933,-71.011816,0.34);void(0);'>Logan</button>
	 <button onclick='javascript:teleportTo(-18.79468,47.464221,1.74);void(0);'>Ivato</button>
	 <button onclick='javascript:teleportTo(-37.006794,174.805291,-1.9);void(0);'>Auckland</button>
	 <button onclick='javascript:teleportTo(35.802413,140.380082,2.61);void(0);'>東京</button>
	 <button onclick='javascript:teleportTo(-1.327478,36.916573,0.93);void(0);'>Jomo Kenyatta</button>
	 <button onclick='javascript:teleportTo(30.139175, 31.406388,-2.27);void(0);'>القاهرة</button>
	 <button onclick='javascript:teleportTo(21.306808,-157.910571,-1.57);void(0);'>Honolulu</button>
	 <button onclick='javascript:teleportTo(1.986282,-157.340623,-1.57);void(0);'>Kiribati</button>
	 <button onclick='javascript:teleportTo(22.296839,113.899813,1.24);void(0);'>赤鱲</button>
	 <button onclick='javascript:teleportTo(47.556488,10.7521188,-1);void(0);'>Emlynn</button>
	 <button onclick='javascript:teleportTo(-22.792799,-43.220387,-1.84);void(0);'>Preston</button>
	 </br>
	<HR WIDTH="100%"/>
	 Feeling adventurous? Enter your own coordinates and fly anywhere on the surface of the earth! 
	 Remember that on our planet (an oblate spheroid), latitude is from -90 to 90 degrees and 
	 longitude is from -180 to 180 degrees.
	 </br>
	<button onclick="javascript:teleport();void(0)">Teleport to:</button>
	<input type="text" id="latlon" size="24" value="53.4359166,-6.261181"/> (latitude,longitude) 
	</br>
	<HR WIDTH="100%"/>
	<i><b>Pro Tip:</b></i> Find a place you're interested in on Google Maps, right click on something nearby that's unlikley to be
	uniqely mapped (a field, lake or similar, not a town or road) then right click and select <i>"Directions from here"</i>.
	The latitude & longitude will appear in the directions box on the left. Just copy these, paste 'em into the box
	above, click the "Teleport" button and voila! You're there.
     </font>
  </div>
</body>
</html>